package cn.springboot.erp.exception;

import cn.springboot.erp.commons.ResponseResult;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalException {

    @ExceptionHandler(Exception.class)
    public ResponseResult exceptionHandler(Exception e){
        e.printStackTrace();
        return ResponseResult.Error().msg("服务器繁忙，请稍后再试");
    }

    @ExceptionHandler(UnauthorizedException.class)
    public ResponseResult unauthorizedException(Exception e){
        e.printStackTrace();
        return ResponseResult.Fail().msg("没有权限，请联系管理员");
    }

    @ExceptionHandler(CustomerException.class)
    public ResponseResult customerException(CustomerException e){
        e.printStackTrace();
        return ResponseResult.Fail().msg(e.getInfo());
    }

    @ExceptionHandler(CustomerNameException.class)
    public ResponseResult customerNameException(CustomerNameException e){
        e.printStackTrace();
        return ResponseResult.Fail().msg(e.getInfo());
    }
}
